#include<iostream>
#include"article.h"
#include "memdata.h"
#include<algorithm>

using namespace std;

using namespace client_server;
int main(){
  //create an newsgroup
	cout<<"start of server"<<endl;
	
	Memdata* serv=new Memdata();
	
	serv->createNewsGroup("newGroup"); 
	
	serv->createNewsGroup("second Group");
	
	serv->createNewsGroup("newGroup"); 
	
	std::cout<<"newsGroup newGroup exists "<< serv->existsNewsgroup("newGroup")<<endl;
	
	std::vector<std::string> names = serv->listAllNewsgroups();
	
	//You have to specify the standard option -std=c++0x when compiling the code under the new C++11 standard.
	
	std::for_each(names.begin(),names.end(),[](std::string name){cout << name << endl;});

	serv->createArticle("newGroup","langer Text...mehr Text...noch mehr Text", "super interesting article", "Sven Svensson");
	
	std::vector<std::string> artnames = serv->listAllArticles("newGroup");
	
	std::for_each(artnames.begin(),artnames.end(),[](std::string name){cout << name << endl;});
  
	std::cout<<"article super interesting article exists "<< serv->existsArticle("newGroup","super interesting article")<<endl; 
	
	std::cout<<"article super-interesting article exists "<< serv->existsArticle("newGroup","super-interesting article")<<endl; 
	
	std::cout <<"delete super interesting article"<<endl;
	//serv->deleteArticle("newGroup","super interesting article");
	std::cout <<"article deleted"<<endl;
	serv->createArticle("newGroup","langer Text...mehr Text...noch mehr Text", "interesting article", "Max Mustermann");  
	std::cout<< "articlecontent of interesting article: "<<serv->readArticle("newGroup","interesting article")<<endl;
	std::cout<<"article super interesting article exists "<< serv->existsArticle("newGroup","super interesting article")<<endl;   
	
	std::cout<<"article interesting article exists "<< serv->existsArticle("newGroup","interesting article")<<endl;  
	
	serv->deleteNewsGroup("newGroup");
 
	cout<<"newsgroup newGroup exists "<< serv->existsNewsgroup("newGroup")<<endl;
 

  
  
  
  
}
